#!/bin/bash

# created by: JiangHongTiao
# jianghongtiao@gmail.com
#
# Arguments
# @param
#
#BUGS
if [ $# == 0 ]
then
  echo "Parameters are not set. Use following params:"
  echo " * all - to remove all temporary files, database tables and sequence"
  echo " * truncate - to remove all temporary files and truncate tables:"
  echo "     * websearchresponse"
  echo "     * classificationstorage"
  exit
fi


PARIS_DIR="/home/xjuraj/Projects/master-thesis/Paris"
if [ `pwd` != "$PARIS_DIR" ]
then
  cd $PARIS_DIR
fi
echo "Working directory: "`pwd`

#remove all temporary files
TEMP_DIR="Temp"
echo "Removing all temporary files from directory: "
echo " * "`pwd`"/$TEMP_DIR/"
rm -rf "./$TEMP_DIR/"
mkdir "$TEMP_DIR"
exit 

#clean database
if [ $1 == "all" ]
then
  echo "Removing all tables and sequences from database"
  sudo su postgres -c psql template1 <<< "TRUNCATE 'downloaditemstatistics', 'proxyfailurestatistics', 'assignedproxystatistics', 'websearchresponse', 'ares_vypis_osoby', 'ares_vypis_stranky_fo', 'classificationstorage', 'sequence', 'ares_help', 'ares_chybova_odpoved', 'ares_error', 'ares_odpovedi', 'ares_odpoved_fo' CASCADE"
elif [ $1 == "truncate" ]
then
  echo "Truncate tables: websearchresponse, classificationstorage"
  psql paris paris << EOF
TRUNCATE websearchresponse, classificationstorage CASCADE;
EOF
else
  echo "Bad option selected"
fi
